package com.wwwarehouse.resource_center.fragment.rules;

import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.View;

import com.wwwarehouse.common.adapter.carddesk.MyFragmentPagerAdapter;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.CustomViewPagerInternal;
import com.wwwarehouse.common.custom_widget.ElasticScrollView;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.tripartite_widget.viewindicator.CirclePageIndicator;
import com.wwwarehouse.resource_center.R;
import com.wwwarehouse.resource_center.fragment.base.MyBaseViewPagerFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Joseph on 2017/8/23.
 *         <p/>
 *         选择已有规则
 */

public class SelectExistingRulesFragment extends MyBaseViewPagerFragment {

    private static final int QUERY_TASK_ALLOCATION_RULEALL = 1;
    CustomViewPagerInternal viewPager;
    CirclePageIndicator pageIndicator;
    ArrayList<Fragment> fragmentList;
    ElasticScrollView elasticScrollView;
    StateLayout loadding;
    MyFragmentPagerAdapter adapter;
    int mNum = 11;

    @Override
    public void setTitle() {
        if (peekFragment() instanceof SelectExistingRulesFragment)
            mActivity.setTitle(getString(R.string.select_exist_rules));
    }

    @Override
    protected void init(View view) {
        loadding = (StateLayout) view.findViewById(R.id.loading);
        elasticScrollView = (ElasticScrollView) view.findViewById(R.id.elastic_scroll);
        viewPager = (CustomViewPagerInternal) view.findViewById(R.id.task_pager);
        pageIndicator = (CirclePageIndicator) view.findViewById(R.id.pager_indicator);
        elasticScrollView.setOnPullListener(new ElasticScrollView.OnPullListener() {
            @Override
            public void onDownPull() {

            }

            @Override
            public void onUpPull() {

            }
        });
    }

    @Override
    protected void loadDatas() {
        //所有的规则列表
        Map<String, Object> map = new HashMap<>();
        map.put("businessId", 1008); //业务单位对应所有规则详情
//        httpPost(ResourceConstant.QUERY_TASK_ALLOCATION_RULEALL, map,QUERY_TASK_ALLOCATION_RULEALL,true,"");
    }

    @Override
    public void requestDatas() {

    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {
        switch (what) {
            case QUERY_TASK_ALLOCATION_RULEALL:
                if (TextUtils.equals("0", commonClass.getCode())) {
//                    ArrayList<TaskDetailedRule>  detailedRules  = (ArrayList<TaskDetailedRule>) JSON.parseArray(commonClass.getData().toString(),TaskDetailedRule.class);
//                        //  loadding.showContentView();
//                    fragmentList = new ArrayList<>();
//                    int count = 0;
//                    if (detailedRules.size() > mNum) {
//                        if ((detailedRules.size() - mNum) % mNum == 0) {
//                            count = (detailedRules.size() - mNum) / mNum;
//                        } else {
//                            count = (detailedRules.size() - mNum) / mNum + 1; // 总共显示多少张卡片
//                        }
//                    } else {
//                        count = 0;
//                    }
//
//                    for (int i = 0; i <= count; i++) {
//                        SelectExistingRulesListFragment categoryFragment = new SelectExistingRulesListFragment();
//                        Bundle bundle = new Bundle();
//                        bundle.putParcelableArrayList("data", detailedRules);
//                        bundle.putInt("pos", i);
//                        bundle.putInt("num", mNum);
//                        categoryFragment.setArguments(bundle);
//                        fragmentList.add(categoryFragment);
//                    }
//
//                    adapter = new MyFragmentPagerAdapter(getChildFragmentManager(), fragmentList);
//                    viewPager.setAdapter(adapter);
//                    pageIndicator.setViewPager(viewPager, 0);
                }
                break;
        }

    }

    @Override
    public void onReLoad(int code) {

    }

}
